<!--
<div class="row ">
    <button type="button" class="btn btn-success" data-toggle="modal" data-target="#addModal">新增</button>
</div>
-->
<form id="query_form" class="form-horizontal">
    <div class="form-group">
        <label for="type" class="col-sm-1 control-label">申请类型</label>
        <div class="col-sm-10">
            <div class="btn-group" data-toggle="buttons" >
                <label class="btn btn-default active">
                    <input type="radio" name="type" value="a" autocomplete="off" checked  >户外广告
                </label>
                <label class="btn btn-default">
                    <input type="radio" name="type" value="b" autocomplete="off"> 临时广告
                </label>
                <label class="btn btn-default">
                    <input type="radio" name="type" value="c" autocomplete="off"> 临时占道
                </label>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label for="type" class="col-sm-1 control-label">申请时间</label>
        <div class="col-sm-10">
            <div class="input-group col-sm-6">
            <input type="text" class="form-control datetimepicker" id="receiving_time" name="receiving_time"
                   placeholder="收件时间" value="{$date}"/>
            </div>
        </div>
    </div>
    <div class="form-group">
        <label for="type" class="col-sm-1 control-label">申请单位</label>
        <div class="col-sm-10">
            <div class="input-group col-sm-6">
            <input type="text" class="form-control" id="danwei_name" name="danwei_name" tabindex="4"
                   placeholder="填写单位名称...">
            </div>
        </div>
    </div>
    <div class="form-group">
        <label for="company_name" class="col-sm-1 control-label">广告公司</label>
        <div class="col-sm-10">
            <div class="input-group col-sm-6">
            <input type="text" class="form-control" id="company_name" name="company_name" tabindex="4"
                   placeholder="填写广告公司...">
            </div>
        </div>
    </div>
    <div class="form-group">
        <label for="type" class="col-sm-1 control-label">道路</label>
        <div class="col-sm-10">
            <select class="form-control" id="daolu" name="daolu">
                <option value="">请选择道路</option>
                <foreach name="daoluData" item="vo">
                    <option value="{$vo.name}">{$vo.name}</option>
                </foreach>
            </select>
        </div>
    </div>
    <div class="form-group group-a">
        <label for="type" class="col-sm-1 control-label">广告主类型</label>
        <div class="col-sm-10">
            <div class="btn-group" data-toggle="buttons">
                <label class="btn btn-default active">
                    <input type="radio" id="a_ad_company_type" name="a_ad_company_type" value="" autocomplete="off" checked  >全部
                </label>
                <label class="btn btn-default ">
                    <input type="radio" name="a_ad_company_type" value="个人" autocomplete="off"> 个人
                </label>
                <label class="btn btn-default">
                    <input type="radio" name="a_ad_company_type" value="社区" autocomplete="off"> 社区
                </label>
                <label class="btn btn-default">
                    <input type="radio" name="a_ad_company_type" value="企业" autocomplete="off"> 企业
                </label>
            </div>
        </div>
    </div>
    <div class="form-group group-a">
        <label for="type" class="col-sm-1 control-label">广告类型</label>
        <div class="col-sm-10">
            <div class="btn-group" data-toggle="buttons">
                <label class="btn btn-default active">
                    <input type="radio" id="a_ad_type_query" name="a_ad_type_query" value="" autocomplete="off"  checked>全部
                </label>
                <label class="btn btn-default ">
                    <input type="radio" name="a_ad_type_query" value="楼顶" autocomplete="off" > 楼顶
                </label>
                <label class="btn btn-default">
                    <input type="radio" name="a_ad_type_query" value="楼面" autocomplete="off"> 楼面
                </label>
                <label class="btn btn-default">
                    <input type="radio" name="a_ad_type_query" value="T型牌" autocomplete="off"> T型牌
                </label>
                <label class="btn btn-default ">
                    <input type="radio" name="a_ad_type_query" value="门头招牌" autocomplete="off"> 门头招牌
                </label>
                <label class="btn btn-default">
                    <input type="radio" name="a_ad_type_query" value="路牌（标牌）" autocomplete="off"> 路牌（标牌）
                </label>
                <label class="btn btn-default">
                    <input type="radio" name="a_ad_type_query" value="霓虹灯（灯箱）" autocomplete="off"> 霓虹灯（灯箱）
                </label>
                <label class="btn btn-default ">
                    <input type="radio" name="a_ad_type_query" value="立柱式电脑喷图" autocomplete="off"> 立柱式电脑喷图
                </label>
                <label class="btn btn-default">
                    <input type="radio" name="a_ad_type_query" value="橱窗" autocomplete="off"> 橱窗
                </label>
                <label class="btn btn-default">
                    <input type="radio" name="a_ad_type_query" value="显示屏" autocomplete="off"> 显示屏
                </label>
                <label class="btn btn-default ">
                    <input type="radio" name="a_ad_type_query" value="候车厅" autocomplete="off"> 候车厅
                </label>
                <label class="btn btn-default">
                    <input type="radio" name="a_ad_type_query" value="其他" autocomplete="off"> 其他
                </label>
            </div>
        </div>
    </div>
    <div class="form-group ">
        <label for="query" class="col-sm-1 control-label"></label>
        <div class="col-sm-10">
            <button type="button" id="query" class="btn btn-primary">搜索</button>&nbsp;&nbsp;
        </div>
    </div>
</form>
<div class="alert alert-success" role="alert">
    搜索（<span id="searchTextString">申请类型：户外广告</span>）
    <button type="button" id="export" class="btn btn-primary">导出</button>&nbsp;&nbsp;
</div>
<table id="list" class="table table-bordered table-striped table-condensed table-hover dataTable" style="margin-top:10px;">
    <thead>
    <tr>
        <th>申请时间</th>
        <th>申请单位</th>
        <th>设置地址</th>
        <th class="">广告公司</th>
        <th class="">广告主类型</th>
        <th class="">广告类型</th>
        <th class="">申请内容</th>
        <th>设置开始日期</th>
        <th>设置结束日期</th>
        <th>批否</th>
        <th>审查意见</th>
        <th>备注</th>
        <th style="width: 16%">操作</th>
    </tr>
    </thead>
</table>
<div id="detailModal" class="modal fade" role="dialog" aria-labelledby="gridSystemModalLabel" aria-hidden="true">
</div>
<div id="shenheModal" class="modal fade" role="dialog" aria-labelledby="gridSystemModalLabel" aria-hidden="true">
</div>
<div id="updateModal" class="modal fade" role="dialog" aria-labelledby="gridSystemModalLabel" aria-hidden="true">
</div>

<link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/dataTables/dataTables.bootstrap.css">

<script type="text/javascript" src="__PUBLIC__/admin/dataTables/jquery.dataTables.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/dataTables/dataTables.bootstrap.js"></script>
<script src="http://cdn.bootcss.com/jquery-validate/1.13.1/jquery.validate.min.js"></script>
<script type="text/javascript" src="__PUBLIC__/admin/datepicker/js/bootstrap-datepicker.js?v=1"></script>
<script src="__PUBLIC__/js/addclear.js"></script>

<link rel="stylesheet" type="text/css" href="__PUBLIC__/admin/fancyBox/jquery.fancybox.css">
<script type="text/javascript" src="__PUBLIC__/admin/fancyBox/jquery.fancybox.js?v=2.1.5"></script>
<script type="text/javascript">
    $(function () {
        $('.datetimepicker').datepicker({
            format: 'yyyy-mm-dd',
            autoclose: true,
        });
        $("input[type='text']").addClear();
    });
    var currType = 'a';
    var hideArray = [5];
    $("input[name='type']").on("change",function () {
        $(".group-a").hide();
        currType = $(this).val();
        if(currType == 'a'){
            $(".group-a").show();
        }
        else{
            $("#a_ad_type_query").click();
            $("#a_ad_company_type").click();
        }
        $('#query').click();
    });
    $('#query').click(function(){
        var type = currType == 'a' ? '户外广告' : (currType == 'b' ? '临时广告' : '临时占道');
        var receiving_time = $("#receiving_time").val();
        var danwei_name = $("#danwei_name").val();
        var company_name = $("#company_name").val();
        var daolu = $("#daolu").val();
        var a_ad_company_type = $("input[name='a_ad_company_type']:checked").val();
        a_ad_company_type = a_ad_company_type ? a_ad_company_type : '全部';
        var a_ad_type_query = $("input[name='a_ad_type_query']:checked").val();
        a_ad_type_query = a_ad_type_query ? a_ad_type_query : '全部';
        var html = '申请类型：' + type;
        if(receiving_time) html += ' 申请时间：' + receiving_time;
        if(danwei_name) html += ' 申请单位：' + danwei_name;
        if(company_name) html += ' 广告公司：' + company_name;
        if(daolu) html += ' 道路：' + daolu;
        if(a_ad_company_type && currType == 'a') html += ' 广告主类型：' + a_ad_company_type;
        if(a_ad_type_query && currType == 'a') html += ' 广告类型：' + a_ad_type_query;
        $("#searchTextString").html(html);
        filterGlobal();
    });
    $("#export").click(function () {
        var url = '__APP__/Record/exportAction?';
        $query = $('#query_form').serialize();
        url = url + $query;
        window.open(url);
    });
    //搜索刷新table
    function filterGlobal () {
        $query = $('#query_form').serialize();
        $('#list').DataTable().search($query,false,true).draw();
    }
        var table =$('#list').dataTable( {
            "bLengthChange": false,
            "iDisplayLength": 20,
            "oLanguage": {
                "sLengthMenu": "每页显示 _MENU_ 条记录",
                "sZeroRecords": "对不起，查询不到任何相关数据",
                "sInfo": "当前显示 _START_ 到 _END_ 条，共 _TOTAL_ 条记录",
                "sInfoEmtpy": "找不到相关数据",
                "sInfoFiltered": "数据表中共为 _MAX_ 条记录)",
                "sProcessing": "正在加载中...",
                "sSearch": "搜索姓名,手机号",
                "oPaginate": {
                    "sFirst":    "第一页",
                    "sPrevious": " 上一页 ",
                    "sNext":     " 下一页 ",
                    "sLast":     " 最后一页 "
                }
            },
            "dom": '<"toolbar">frtip',
            "bProcessing": true,
            "bServerSide": true,
            "sPaginationType": "full_numbers",
            "processing": true,
            "serverSide": true,
            "ajax": {
                "url": "__APP__/Record/index/ajax/1",
                "type": "POST"
            },
            "columns": [
                { "data": "receiving_time" },
                { "data": "danwei_name" },
                { "data": "address" },
                { "data": "company_name" },
                { "data": "a_ad_company_type" },
                { "data": "a_ad_type" },
                { "data": "bc_neirong" },
                { "data": "start_set_time" },
                { "data": "end_set_time" },
                { "data": "status" },
                { "data": "yijian" },
                { "data": "remark" },
                { "data": "id" }
            ],
            "columnDefs": [
                {
                    "orderable": false,
                    "targets": 0
                },
                {
                    "orderable": false,
                    "targets": 1
                },
                {
                    "render": function ( data, type, row ) {
                        var optHtml = row.daolu + row.address;
                        return optHtml;
                    },
                    "orderable": false,
                    "targets": 2
                },
                {
                    "orderable": false,
                    "targets": 3
                },
                {
                    "orderable": false,
                    "targets": 4
                },
                {
                    "orderable": false,
                    "targets": 5
                },
                {
                    "render": function ( data, type, row ) {
                        var format_data = data;
                        var nowLength = data.length;
                        if(nowLength>12){
                            format_data = data.substr(0,12)+' . . . ';
                        }
                        var optHtml = '<span class="neirong" title="'+ data +'">'+ format_data +'</span>';
                        return optHtml;
                    },
                    "orderable": false,
                    "targets": 6
                },
                {
                    "orderable": false,
                    "targets": 7
                },
                {
                    "orderable": false,
                    "targets": 8
                },
                {
                    "render": function ( data, type, row ) {
                        var optHtml = data == 0 ? '未审核':(data == 1 ?'通过':'不通过');
                        return optHtml;
                    },
                    "orderable": false,
                    "targets": 9
                },
                {
                    "orderable": false,
                    "targets": 10
                },
                {
                    "orderable": false,
                    "targets": 11
                },
                {
                    "render": function ( data, type, row ) {
                        //var optHtml = '<a class="btn btn-default viewUser" href="#" role="button" data-row=\''+ JSON.stringify(row) +'\'>查看</a>';
                        var a_biaoge = '';
                        if(row.status == 1 && row.type=='a'){
                            a_biaoge = '<a class="btn btn-default " href="__APP__/Info/dengjibiao/id/'+ row.id +'" target="_blank" role="button" >备案登记表</a>';
                        }
                        var optHtml = '<a class="btn btn-default " href="__APP__/Info/a/id/'+ row.id +'" target="_blank" role="button" >表格</a>'+
                            '<a href="#" class="btn btn-default detailRow" data-id="'+ row.id +'">详情</a>'+
                            a_biaoge +
                            '<br/><a href="#" class="btn btn-default modifyRow" data-id="'+ row.id +'" >修改</a>'+
                            '<a href="#" class="btn btn-default shenheRow" data-id="'+ row.id +'" >审核</a>'+
                            '<a href="#" class="btn btn-danger deleteRow"  data-id="'+ row.id +'" >删除</a>';
                        return optHtml;
                    },
                    "orderable": false,
                    "targets": 12
                },
                { "visible": false,  "targets": hideArray }
            ],
            "drawCallback": function( settings) {
                var type = currType;
                switch (type){
                    case 'b':
                        table.fnSetColumnVis(4,false,false);
                        table.fnSetColumnVis(5,false,false);
                        table.fnSetColumnVis(6,true,false);
                        break;
                    case 'c':
                        table.fnSetColumnVis(4,false,false);
                        table.fnSetColumnVis(5,false,false);
                        table.fnSetColumnVis(6,true,false);
                        break;
                    default:
                        table.fnSetColumnVis(4,true,false);
                        table.fnSetColumnVis(5,true,false);
                        table.fnSetColumnVis(6,false,false);
                        break;
                }
                $("#list_filter").hide();
                $(".shenheRow").on("click",function(){
                    var id = $(this).data('id');
                    var target = "#shenheModal";
                    $(target).html('');
                    $(target).load("__URL__/shenhe/id/"+id);
                    $(target).modal("show");
                });
                $(".detailRow").on("click",function(){
                    var id = $(this).data('id');
                    var target = "#detailModal";
                    $(target).html('');
                    $(target).load("__URL__/one/id/"+id);
                    $(target).modal("show");
                });
                $(".modifyRow").on("click",function(){
                    var id = $(this).data('id');
                    var target = "#updateModal";
                    $(target).html('');
                    $(target).load("__URL__/update/id/"+id);
                    $(target).modal("show");
                });
                $(".deleteRow").on("click",function(){
                    var r=confirm("删除操作不可恢复，确定删除吗？!");//window.confirm("Press a button");
                    if (r==true)
                    {
                        var id = $(this).data('id');
                        $.ajax({
                            url: "__URL__/del",
                            dataType: "json",
                            type: "POST",
                            data: {
                                id: id
                            },
                            success: function (a) {
                                $('#list').DataTable().ajax.reload();
                                alertMsg('操作成功', {icon:'success'});
                            },
                            error: function (a) {
                                alertMsg('网络不好，操作失败', {icon:'warning'});
                            }
                        })
                    }
                });
//                $("a[data-toggle=modal]").on("click",function(){
//                    //$(".modal-backdrop").remove();
//                    var target = $(this).attr('data-targetID');
//                    var url = $(this).attr('data-href');
//                    $(target).html('');
//                    $(target).load(url);
//                    $(target).modal("show");
//                    return ;
//                });
//                $(".viewUser").on("click",function(){
//                    var row = JSON.parse($(this).attr('data-row'));
//                    $("#userInfoModal").modal("show");
//                    return false;
//                });
            }
            //"order": [[ 4, 'asc' ], [ 5, 'desc' ]],
        } );

    $(document).ready(function() {
        $('#query').click();
    });
</script>
